package com.huawei.M01.iterator;

import java.util.Arrays;

public class NumberOfPairs {
    public int[] numberOfPairs(int[] nums) {
        if (nums.length == 1) {
            return new int[]{0, 1};
        }
        // 先对数组进行排序
        Arrays.sort(nums);
        int countOfPairs = 0;
        int countOfSingle = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i + 1 < nums.length && nums[i] == nums[i + 1]) {
                countOfPairs++;
                i++;
            } else {
                countOfSingle++;
            }
        }
        return new int[]{countOfPairs, countOfSingle};
    }
}
